<html>
<head>	
	<script language="javascript">
		function validasi(form){
		  if ((form.id_member.value == "") && (form.password.value == "") && (form.namalengkap.value == "") && (form.tgl_lahir.value == "") && (form.jenis_kelamin.value == "") && (form.status.value == "") && (form.alamat.value == "") && (form.gol_darah.value == "") ){
			alert("Data belum terisi.");
			form.id_member.focus();
			return (false);
		  }
		  
		  if (form.id_member.value == ""){
			alert("Anda belum mengisikan id Member.");
			form.id_member.focus();
			return (false);
		  }
			 
		  if (form.password.value == ""){
			alert("Anda belum mengisikan password.");
			form.password.focus();
			return (false);
		  }
		  
		  if (form.namalengkap.value == ""){
			alert("Anda belum mengisikan nama lengkap.");
			form.namalengkap.focus();
			return (false);
		  }
		  if (form.tgl_lahir.value == ""){
			alert("Anda belum mengisikan tanggallahir.");
			form.tgl_lahir.focus();
			return (false);
		  }
		  if (form.jenis_kelamin.value == ""){
			alert("Anda belum mengisikan jenis kelamin.");
			form.jenis_kelamin.focus();
			return (false);
		  }
		  if (form.status.value == ""){
			alert("Anda belum mengisikan status.");
			form.status.focus();
			return (false);
		  }
		  if (form.alamat.value == ""){
			alert("Anda belum mengisikan alamat.");
			form.alamat.focus();
			return (false);
		  }
		  if (form.gol_darah.value == ""){
			alert("Anda belum mengisikan golongan darah.");
			form.gol_darah.focus();
			return (false);
		  }
		  return (true);
		}
	</script>
</head>
</html>
<?php
$aksi="modul/mod_member/aksi_member.php";
switch($_GET[act]){
  // Tampil Data Member
  default:
    echo "<h2>Data Member</h2>
          <p><input type=button value='Tambah Member' onclick=location.href='?module=member&act=tambahmember'></p>";?>
		  <div class="search">
				<form method="POST" action="?module=member&act=carimember">
					<fieldset>
						<input class="text" type="text" name="kata" onblur="if(this.value=='')this.value='pencarian member...';" onclick="if(this.value=='pencarian member...')this.value='';" name="search" value="pencarian member..." />
						<input class="submit" type="submit" value="" />
					</fieldset>
				</form>
			</div>
          <?php echo "<table id='rounded-corner'>
          <thead><tr><th scope='col' class='rounded-company'>No</th><th>Id Member</th><th>Nama Lengkap</th><th>Tanggal Lahir</th><th>Jenis Kelamin</th><th>Status</th><th>Gol.</th><th>Aktifasi</th><th>Edit</th></tr></thead>";
    
	$p      = new Paging;
    $batas  = 10;
    $posisi = $p->cariPosisi($batas);

    if ($_SESSION[leveluser]=='admin'){
      $tampil = mysql_query("SELECT * FROM member ORDER BY id_member DESC LIMIT $posisi,$batas");
    }
    else{
      $tampil=mysql_query("SELECT * FROM member 
                           WHERE username='$_SESSION[namauser]'       
                           ORDER BY id_member DESC LIMIT $posisi,$batas");
    }
    
	$no= $posisi+1;
    while ($r=mysql_fetch_array($tampil)){
	$tgl_lahir=tgl_indo($r[tgl_lahir]);
      echo "<tr><td>$no</td>
                <td>$r[id_member]</td>
				<td>$r[namalengkap]</td>
				<td>$tgl_lahir</td>
				<td>$r[jenis_kelamin]</td>
				<td>$r[status]</td>
				<td>$r[gol_darah]</td>
				<td>$r[aktifasi]</td>
                <td><a href=?module=member&act=editmember&id=$r[id_member]><img border=0 title='' alt='' src='images/user_edit.png'></a></td>
		    </tr>";
    $no++;
    }
    echo "</table>";
	
			
		if ($_SESSION[leveluser]=='admin'){
      $jmldata = mysql_num_rows(mysql_query("SELECT * FROM member"));
    }
    else{
      $jmldata = mysql_num_rows(mysql_query("SELECT * FROM member WHERE username='$_SESSION[namauser]'"));
    }  
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>Hal: $linkHalaman</div><br>";
	
	
    break;
  
  case "tambahmember":
    echo "<h2>Tambah Member</h2>
          <form method=POST action='$aksi?module=member&act=input' enctype='multipart/form-data' onSubmit='return validasi(this)'>
          <table>
		  <tr><td>Id Member *)</td><td>  : <input type=text name='id_member' size=10></td></tr>
		  <tr><td>Password *)</td><td>  : <input type=password name='password' size=10></td></tr>
          <tr><td>Nama Lengkap *)</td><td>  : <input type=text name='namalengkap' size=50></td></tr>
		  <tr><td>Tanggal Lahir *)</td><td> : <input type = text name='tgl_lahir' id='tanggal'></td></tr>
		  <tr><td>Jenis Kelamin *)</td><td>  : <input type=radio name='jenis_kelamin' value='Wanita'>Wanita 
                                         <input type=radio name='jenis_kelamin' value='Pria'>Pria  </td></tr>
		  <tr><td>Status *)</td>  <td> : 
			  <select name='status'>
				<option value=''>- Pilih Status -</option>
				<option value='Pegawai'>Pegawai</option>
				<option value='Pasangan'>Pasangan</option>
				<option value='Anak Ke 1'>Anak Ke 1</option>
				<option value='Anak Ke 2'>Anak Ke 2</option>
				<option value='Anak Ke 3'>Anak Ke 3</option>
			  </select>
          <tr><td>Alamat *)</td><td> : <textarea name='alamat'  style='width: 550px; height: 100px;'></textarea></td></tr>
		  <tr><td>Gol. Darah *)</td><td>  : <input type=radio name='gol_darah' value='A'>A 
                                         <input type=radio name='gol_darah' value='B'>B 
										 <input type=radio name='gol_darah' value='O'>O 
										 <input type=radio name='gol_darah' value='AB'>AB 
							</td></tr>
          <tr><td>Foto</td><td> : <input type=file name='fupload' size=40></td></tr>
		  <tr><td colspan=2>*) Harus diisi.</td></tr>
          <tr><td colspan=2><input type=submit value=Simpan>
                            <input type=button value=Batal onclick=self.history.back()></td></tr>
          </table></form><br><br><br>";
     break;
	
  case "editmember":
    $edit = mysql_query("SELECT * FROM member WHERE id_member='$_GET[id]'");
    $r    = mysql_fetch_array($edit);

    echo "<h2>Edit Member</h2>
          <form method=POST enctype='multipart/form-data' action=$aksi?module=member&act=update>
          <input type=hidden name=id value=$r[id_member]>
          <table>
		  <tr><td>Id Member</td><td>   :   <input disabled='' type=text name='id' size=10 value='$r[id_member]'></td></tr>
		  <tr><td>Password</td><td>   :   <input disabled='' type=password name='password' size=15 value='$r[password]'></td></tr>
          <tr><td>Nama Lengkap</td><td>   :   <input type=text name='namalengkap' size=50 value='$r[namalengkap]'></td></tr>
		  <tr><td>Tanggal Lahir</td><td>   :   <input type=text name='tgl_lahir' size=15 value='$r[tgl_lahir]'></td></tr>";
			if ($r[jenis_kelamin]=='Wanita'){
			  echo "<tr><td>Jenis Kelamin</td> <td> : <input type=radio name='jenis_kelamin' value='Wanita' checked>Wanita  
											  <input type=radio name='jenis_kelamin' value='Pria'>Pria </td></tr>";
			}
			else{
			  echo "<tr><td>Jenis Kelamin</td> <td> : <input type=radio name='jenis_kelamin' value='Wanita'>Wanita  
											  <input type=radio name='jenis_kelamin' value='Pria' checked>Pria</td></tr>";
			}
			echo "
			<tr><td>Status</td>  <td> : <select name='status'>";
			if ($r[status]=='Pegawai'){
				echo "
					<option value=0>- Pilih Status -</option>
					<option value='Pegawai' selected>Pegawai</option>
					<option value='Pasangan'>Pasangan</option>
					<option value='Anak Ke 1'>Anak Ke 1</option>
					<option value='Anak Ke 2'>Anak Ke 2</option>
					<option value='Anak Ke 3'>Anak Ke 3</option>
				";
			  }
			else if ($r[status]=='Pasangan'){
				echo "
					<option value=0>- Pilih Status -</option>
					<option value='Pegawai'>Pegawai</option>
					<option value='Pasangan' selected>Pasangan</option>
					<option value='Anak Ke 1'>Anak Ke 1</option>
					<option value='Anak Ke 2'>Anak Ke 2</option>
					<option value='Anak Ke 3'>Anak Ke 3</option>
				";
			  }
			else if ($r[status]=='Anak Ke 1'){
				echo "
					<option value=0>- Pilih Status -</option>
					<option value='Pegawai'>Pegawai</option>
					<option value='Pasangan'>Pasangan</option>
					<option value='Anak Ke 1' selected>Anak Ke 1</option>
					<option value='Anak Ke 2'>Anak Ke 2</option>
					<option value='Anak Ke 3'>Anak Ke 3</option>
				";
			  }
			else if ($r[status]=='Anak Ke 2'){
				echo "
					<option value=0>- Pilih Status -</option>
					<option value='Pegawai'>Pegawai</option>
					<option value='Pasangan'>Pasangan</option>
					<option value='Anak Ke 1'>Anak Ke 1</option>
					<option value='Anak Ke 2' selected>Anak Ke 2</option>
					<option value='Anak Ke 3'>Anak Ke 3</option>
				";
			  }
			else {
				echo "
					<option value=0>- Pilih Status -</option>
					<option value='Pegawai'>Pegawai</option>
					<option value='Pasangan'>Pasangan</option>
					<option value='Anak Ke 1'>Anak Ke 1</option>
					<option value='Anak Ke 2'>Anak Ke 2</option>
					<option value='Anak Ke 3' selected>Anak Ke 3</option>
				";
			}
			echo "</select></td></tr>
          <tr><td>Alamat</td><td>: <textarea name='alamat' style='width: 550px; height: 100px;'>$r[alamat]</textarea></td></tr>";
			if ($r[gol_darah]=='A'){
			  echo "<tr><td>Gol.Darah</td> <td> : <input type=radio name='gol_darah' value='A' checked>A  
											  <input type=radio name='gol_darah' value='B' >B
											  <input type=radio name='gol_darah' value='O' >O
											  <input type=radio name='gol_darah' value='AB' >AB </td></tr>";
			}
			else if ($r[gol_darah]=='B'){
			  echo "<tr><td>Gol.Darah</td> <td> : <input type=radio name='gol_darah' value='A' >A  
											  <input type=radio name='gol_darah' value='B' checked>B
											  <input type=radio name='gol_darah' value='O' >O
											  <input type=radio name='gol_darah' value='AB' >AB </td></tr>";
			}
			else if ($r[gol_darah]=='O'){
			  echo "<tr><td>Gol.Darah</td> <td> : <input type=radio name='gol_darah' value='A' >A  
											  <input type=radio name='gol_darah' value='B' >B
											  <input type=radio name='gol_darah' value='O' checked>O
											  <input type=radio name='gol_darah' value='AB' >AB </td></tr>";
			}
			else {
			  echo "<tr><td>Gol.Darah</td> <td> : <input type=radio name='gol_darah' value='A' >A  
											  <input type=radio name='gol_darah' value='B' >B
											  <input type=radio name='gol_darah' value='O' >O
											  <input type=radio name='gol_darah' value='AB' checked>AB </td></tr>";
			}
			echo "
          <tr><td>Foto</td><td>  :   <img src='foto/foto_member/$r[gambar]' style='width:150px; height: 200px;'></td></tr>
          <tr><td>Ganti Gbr</td><td> : <input type=file name='fupload' size=30> *)</td></tr>
          <tr><td colspan=2>*) Apabila gambar tidak diubah, dikosongkan saja.</td></tr>
          <tr><td colspan=2><input type=submit value=Update>
                            <input type=button value=Batal onclick=window.location='media.php?module=member'></td></tr>
          </table></form>";
    break;  
	
	case "carimember";
	$kata = trim($_POST[kata]);

	  // pisahkan kata per kalimat lalu hitung jumlah kata
	  $pisah_kata = explode(" ",$kata);
	  $jml_katakan = (integer)count($pisah_kata);
	  $jml_kata = $jml_katakan-1;

	  $cari = "SELECT * FROM member WHERE " ;
		for ($i=0; $i<=$jml_kata; $i++){
		  $cari .= "namalengkap LIKE '%$pisah_kata[$i]%' OR status LIKE '%$pisah_kata[$i]%' OR id_member LIKE '%$pisah_kata[$i]%' OR jenis_kelamin LIKE '%$pisah_kata[$i]%' OR gol_darah LIKE '%$pisah_kata[$i]%' OR aktifasi LIKE '%$pisah_kata[$i]%'";
		  if ($i < $jml_kata ){
			$cari .= " OR ";
		  }
		}
	  $hasil  = mysql_query($cari);
	  $ketemu = mysql_num_rows($hasil);
	  
		if ($ketemu > 0){
		echo "<p>Ditemukan <b>$ketemu</b> member dengan data <font style='background-color:#00FFFF'><b>$kata</b></font> : </p>"; 
		
		  
		  echo "<table id='rounded-corner'>
          <thead><tr><th scope='col' class='rounded-company'>No</th><th>Id Member</th><th>Nama Lengkap</th><th>Tanggal Lahir</th><th>Jenis Kelamin</th><th>Status</th><th>Gol.</th><th>Aktifasi</th><th>Edit</th></tr></thead>";
    
			$p      = new Paging;
			$batas  = 10;
			$posisi = $p->cariPosisi($batas);

			if ($_SESSION[leveluser]=='admin'){
			  $tampil = mysql_query($cari." DESC LIMIT $posisi,$batas");
			}
			else{
			  $tampil=mysql_query($cari." AND WHERE username='$_SESSION[namauser]'       
								   ORDER BY id_member DESC LIMIT $posisi,$batas");
			}
			
			$no= $posisi+1;
			while($t=mysql_fetch_array($hasil)){
			  echo "<tr><td>$no</td>
						<td>$t[id_member]</td>
						<td>$t[namalengkap]</td>
						<td>$t[tgl_lahir]</td>
						<td>$t[jenis_kelamin]</td>
						<td>$t[status]</td>
						<td>$t[gol_darah]</td>
						<td>$t[aktifasi]</td>
						<td><a href=?module=member&act=editmember&id=$t[id_member]><img border=0 title='' alt='' src='images/user_edit.png'></a></td>
					</tr>";
			$no++;
			}
			echo "</table>";
			
					
			if ($_SESSION[leveluser]=='admin'){
			  $jmldata = mysql_num_rows(mysql_query($cari));
			}
			else{
			  $jmldata = mysql_num_rows(mysql_query($cari." WHERE username='$_SESSION[namauser]'"));
			}  
			$jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
			$linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

			echo "<div id=paging>Hal: $linkHalaman</div><br>
			";
		}                                                          
	  else{
		echo "<p>Tidak ditemukan data member <b>$kata</b></p>";
	  }
	  			echo "<input type=button value=Back onclick=window.location='media.php?module=member'>";
	break;
}
?>
